package com.roamer.javase.demo.leecode;

/**
 * @author roamer
 * @version v1.0
 * @date 2021/3/20 01:01
 */
public class LongestSubstring {
    public int find(String str, String s) {
        // 记录每个单词结尾的最长子串
        int[] dp = new int[26];
        int curLength = 1;
        int count = 0;
        int index = -1;
        for (int i = 0; i < str.length(); ++i) {
            if (i != 0 && (str.charAt(i) - str.charAt(i - 1) == 1 || str.charAt(i - 1) - str.charAt(i) == 25)) {
                ++curLength;
                count++;
            } else {
                count = 0;
                curLength = 1;
            }
            dp[str.charAt(i) - 'a'] = Math.max(dp[str.charAt(i) - 'a'], curLength);
        }

        int res = 0;
        for (int i = 0; i < 26; ++i)
            res += dp[i];
        return res;
    }
}
